import { concatPic, createdSong } from "common/js/util";

export default {
    originSingerList(state) {
        if (!state.singerList.length) return
        let singerLists = state.singerList;
        let obj = {
            hot: {
                name: "热门",
                list: []
            }
        }
        singerLists.forEach(item => {
            obj.hot.list.length < 10 && obj.hot.list.push({
                name: item.Fsinger_name,
                id: item.Fsinger_mid,
                src: concatPic(item.Fsinger_mid)
            })

            if (!obj[item.Findex]) {
                obj[item.Findex] = {
                    name: item.Findex,
                    list: []
                }
            }
            obj[item.Findex].list.push({
                name: item.Fsinger_name,
                id: item.Fsinger_mid,
                src: concatPic(item.Fsinger_mid)
            })
        })

        let hotArr = [];
        let arr = [];
        hotArr.push(obj.hot);
        Object.keys(obj).forEach(item => {
            let reg = /[A-Z]/;
            if (!item.match(reg)) return
            arr.push(obj[item])
        })
        arr.sort((a, b) => {
            return a.name.charCodeAt() - b.name.charCodeAt()
        })
        singerLists = [...hotArr, ...arr]

        return singerLists

    },
    nomarlSongList({ songList }) {
        if (!songList) return null;
        let arr = [];
        songList.list.forEach(item => {

            arr.push(createdSong(item.musicData, songList.singer_id, songList.singer_mid, songList.singer_name))
        })


        return arr
    }
}